<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>教练信息页|私教预约系统</title>
    <link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css"  rel="stylesheet"  type="text/css" >
</head>

<body>

<h1 class="col-sm-offset-5"><span class="label label-default">您的个人信息</span></h1>
<form class="form-horizontal">
    <div class="form-group">

    </div>
    <div class="form-group">

    </div>

    <div class="form-group">
        <label for="inputTrainerImage" class="col-sm-2 control-label">头像</label>
        <div class="col-sm-5">
            <img id="inputTrainerImage" alt="图片加载失败" title="点击更改头像" class="img-rounded"  style="width: 150px;height: 150px;" onclick="changeImage()">
        </div>
    </div>

    <div class="form-group">
        <label for="inputTrainerName" class="col-sm-2 control-label">姓名</label>
        <div class="col-sm-3">
            <input type="text" class="form-control" id="inputTrainerName" placeholder="姓名">
        </div>
    </div>

    <div class="form-group">
        <label for="inputTrainerAge" class="col-sm-2 control-label">年龄</label>
        <div class="col-sm-1">
            <input type="text" class="form-control" id="inputTrainerAge" placeholder="年龄">
        </div>
    </div>

    <div class="form-group">
        <label for="inputTrainerSex" class="col-sm-2 control-label">性别</label>
        <div class="col-sm-2">
            <select class = "selectpicker form-control" id = "inputTrainerSex"  title="请选择">
                <option value="1">男</option>
                <option value="2">女</option>
            </select>
        </div>
    </div>


    <div class="form-group">
        <label for="inputTrainerCome" class="col-sm-2 control-label">入职时间</label>
        <div class="col-sm-2">
            <input type="text" class="form-control" id="inputTrainerCome" readonly="true" placeholder="入职时间">
        </div>
    </div>

    <div class="form-group">
        <label for="inputTrainerExperience" class="col-sm-2 control-label">职业经验</label>
        <div class="col-sm-1">
            <input type="text" class="form-control" id="inputTrainerExperience" readonly="true" placeholder="职业经验">
        </div>
    </div>


    <div class="form-group">
        <label for="inputTrainerPhonenumber" class="col-sm-2 control-label">电话号码</label>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="inputTrainerPhonenumber" readonly="true" placeholder="">
        </div>
    </div>

    <div class="form-group">
        <label for="inputTrainerMind" class="col-sm-2 control-label">执教理念</label>
        <div class="col-sm-6">
            <input type="text" class="form-control" id="inputTrainerMind" placeholder="">
        </div>
    </div>

    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" class="btn btn-info" onclick="saveEdition()">确认修改</button>
        </div>
    </div>
</form>
</body>


<script src="../jquery/jquery-3.4.1.min.js"></script>
<script src="../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function(){

        let currentTrainerPhone = $.cookie("trainerphone");

        jQuery.post("/getTrainerInfoByPhone", {"trainerPhone": currentTrainerPhone}, function(rst) {

            //头像
            let imagePath = rst.trainerImage;
            $("#inputTrainerImage").attr('src',imagePath);

            $("#inputTrainerName").val(rst.trainerName);

            $("#inputTrainerAge").val(rst.trainerAge);

            let sexId = 1;
            if (rst.trainerSex == '女'){
                sexId = 2;
            }

            $("#inputTrainerSex").val(sexId);

            $("#inputTrainerCome").val(rst.trainerOnJobTime);

            $("#inputTrainerExperience").val(rst.trainerExperience);

            $("#inputTrainerPhonenumber").val(rst.trainerPhone);

            $("#inputTrainerMind").val(rst.trainerPhilosophy);

        })
    });

    function saveEdition(){

        let currentTrainerId = $.cookie("trainerid");

        let name = jQuery("#inputTrainerName").val();
        let options = $("#inputTrainerSex option:selected");
        let sexId = options.val();
        let sex = options.text();
        let age = jQuery("#inputTrainerAge").val();
        let mind = jQuery("#inputTrainerMind").val();

        jQuery.post("/editTrainerInfo", {"trainerName": name, "trainerSex": sex, "trainerAge": age, "trainerPhilosophy": mind, "trainerId": currentTrainerId}, function(rst) {
            alert(rst);
            if(rst == "修改成功")
            {
                window.location.reload();
            }
        })
    }

    function changeImage(){
        window.location.href="trainerChangeImage.html";
    }
</script>


</html>
